/*
 *  cylk_imageManagement.h
 *  cylk
 *
 *  Types and utilities for managing 2D and 3D images.
 *  
 *  These should have no dependencies except for standard library.
 *
 *  Created by Benjamin Heasly on 7/14/09.
 *  Copyright 2009 __MyCompanyName__. All rights reserved.
 *
 */
#ifndef CYLK_IMAGEMANAGEMENT
#define CYLK_IMAGEMANAGEMENT

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

// hold 3D image data
typedef struct {
    short *pt;
    int nx;
    int ny;
    int nz;
    int nVoxels;
    float dx;
    float dy;
    float dz;
} cylkImage;

// hold 2D image data
typedef struct {
    short *pt;
    int nx;
    int ny;
    int nVoxels;
    float dx;
    float dy;
} cylkSlice;

cylkImage new_cylkImage						(int nx, int ny, int nz, float dx, float dy, float dz);
cylkImage new_cylkImageLikeExisting			(cylkImage *existing);
void destroy_cylkImage						(cylkImage *im);

cylkSlice new_cylkSlice						(int nx, int ny, float dx, float dy);
cylkSlice new_cylkSliceFromCylkImage		(cylkImage *im, int slicenum, int slicedim);
void destroy_cylkSlice						(cylkSlice *sl);

void subscriptsToIndex						(cylkImage *im, int x, int y, int z, long *index);
void indexToSubscripts						(cylkImage *im, int *x, int *y, int *z, long index);

long indexOfMaxImageVoxel					(cylkImage *im);
int indexesOfVoxelsNeighboringImageVoxel	(cylkImage *im, long voxelIndex, long *neighborIndexes);
int insertSliceIntoImage					(cylkSlice *inputSlice, cylkImage *outputImage, int slicenum,int slicedim);

#endif